﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;

namespace RooHui.Infrastructure.Entities.Repository
{
    [Table("U_RoleModule")]
    public class U_RoleModule : IEntity<U_RoleModule>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }
        public int RoleID { get; set; }
        public int ModuleID { get; set; }

        public override U_RoleModule Find(string key)
        {
            int Id = Int32.Parse(key);
            return Find(c => c.ID == Id);
        }

        public override U_RoleModule Find(System.Linq.Expressions.Expression<Func<U_RoleModule, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.RoleModule.FirstOrDefault(where);
                if (item != null)
                {
                    this.ID = item.ID;
                    this.ModuleID = item.ModuleID;
                    this.RoleID = item.RoleID;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<U_RoleModule, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.RoleModule.Any(where);
            }
        }
    }
}